APP_NAME = 聊天助手
SRC = ollama_chat.c
OBJ = $(SRC:.c=.o)

# 编译器配置
CC = gcc
CFLAGS = -O2 -Wall -Wextra $(shell pkg-config --cflags gtk+-3.0 json-c)
LDLIBS = $(shell pkg-config --libs gtk+-3.0 json-c) -lcurl

# 平台判断
ifeq ($(OS),Windows_NT)
    EXE = $(APP_NAME).exe
    RUN_CMD = ./$(EXE)
else
    UNAME_S := $(shell uname -s)
    ifeq ($(UNAME_S),Darwin)
        EXE = $(APP_NAME)
        RUN_CMD = ./$(EXE)
    else
        EXE = $(APP_NAME)
        RUN_CMD = ./$(EXE)
    endif
endif

all: $(EXE)

$(EXE): $(OBJ)
	$(CC) $(CFLAGS) $^ -o $@ $(LDLIBS)

%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	rm -f *.o $(EXE)

run: $(EXE)
	$(RUN_CMD)

.PHONY: all clean run
